package com.nsgf.library.data.bean;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.nsgf.library.BR;
import com.nsgf.library.R;
import com.nsgf.library.base.BaseApplication;

public class ChartDataBean extends BaseObservable implements Parcelable {

    public ChartDataBean(){}
    protected ChartDataBean(Parcel in) {
        color = in.readInt();
        chartLineDataSet = in.readByte() != 0;
        chartTitles = in.readString();
    }

    public static final Creator<ChartDataBean> CREATOR = new Creator<ChartDataBean>() {
        @Override
        public ChartDataBean createFromParcel(Parcel in) {
            return new ChartDataBean(in);
        }

        @Override
        public ChartDataBean[] newArray(int size) {
            return new ChartDataBean[size];
        }
    };

    @Bindable
    public int getColor() {
        return isChartLineDataSet() ? color : BaseApplication.getInstance().getResources().getColor(R.color.color_666666);
    }

    public void setColor(int color) {
        this.color = color;
        notifyPropertyChanged(BR.color);
    }

    @Bindable
    public boolean isChartLineDataSet() {
        return chartLineDataSet;
    }

    public void setChartLineDataSet(boolean chartLineDataSet) {
        this.chartLineDataSet = chartLineDataSet;
        notifyPropertyChanged(BR.chartLineDataSet);
    }

    public String getChartTitles() {
        return chartTitles;
    }

    public void setChartTitles(String chartTitles) {
        this.chartTitles = chartTitles;
    }

    private int color;
    private boolean chartLineDataSet;
    private String chartTitles;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(color);
        dest.writeByte((byte) (chartLineDataSet ? 1 : 0));
        dest.writeString(chartTitles);
    }
}
